Page({
  data: {
    point: '', // 小区
    building: '', // *单元/号楼
    rooms: [], // 房间数组 4-8
  },
  // point=正义路3号院&building=1号楼
  onLoad({ point, building }) {
    this.fakeData(point, building)
  },
  fakeData(point, building) {
    // 1.1 确定房间的数量 4-8
    const size = Math.floor(Math.random() * 5) + 4
    const rooms = []

    // 1.2 遍历产生房间号
    for (let i = 0; i < size; i++) {
      // 1.2.1 产生随机楼层(1-20)
      const floor = Math.floor(Math.random() * 20) + 1
      // 1.2.2 产生随机房间号
      const no = Math.floor(Math.random() * 4) + 1
      // 1.2.3 组合房间号
      const room = [floor, '0', no].join('')
      // 1.2.5 数组去重
      if (rooms.includes(room)) continue
      // 1.2.4 把房间放入房间数组
      rooms.push(room)
    }

    // 1.3 更新数据
    this.setData({
      point,
      building,
      rooms,
    })
  },
  goForm(ev) {
    // 获取小区和楼栋信息
    const { point, building } = this.data
    wx.navigateTo({
      url: `/house_pkg/pages/form/index?point=${point}&building=${building}&room=${ev.mark.room}`,
    })
  },
})
